Bug fixes, removed redundant code