Bug fixes and removal of certain code