Restored changes from dev branchAfter there were merging problems with dev, this is an attempt to restore recent changes.