added rack-cors and did a bunch of refactoring.