Javascript code cleanup