Refactored a few lines to make it a little more readable