cleaned up js code a bit