Merged several bug fixes