major refactoring and minor changes to follow Django best practices