Pull Request for Engine Refactoring

I've tried to consolidate the commits somewhat; but the old commits are still in the history.