added ajax and refactored betting