Did some factoring and added a few helper methods.