Improved closureness, added AJAX calls to save and load segments