Fixed problem with terrain/factories.py, refactored code and improved test coverage