Did some refactoring to make life easier