Did some refactoring to keep it simple