Cleaned up js a bit; fixed bugs.