Fixing Javascript errors