this is very sad, completely rewrote js for clarity, but t now have to completely rewrite it again to use promises