Refactoring to PostgreSQL and a non-appengine server + some fixes