Cleaning up and bug fixing