fixed bugs, cleaned up js