Cleaned up js code a bit.