refactor code, add postgres db