cleaned up code, because javascript is insane.