Refactored Javascript, fixed fatal chrome bug.