Engine refactor

Some cleanup to prepare for #72