Removed redundant code, minor bug fixes