Cleaned up the javascript (made it simpler)