Cleaned up the js and changed api