Refactored a little for readability