Changed the code to be clearer and (subsequently) cleaner