Cleaned up javaScript code