Cleaned up javascript code