Refactored project system

Used some code from the Python project to refactor the project system to
fix some of the known issues and make the code simpler.