Did a little refactoring to make things more clear