refactor main code base to removed duplicated code and improve javascript as well as allow for custom options