Fixed several bug fixes