Fixed various bugs
Bug fixes