clean up code, made into js object