Incorporated various bug fixes

Fixed various bugs