Refactored to make more nice.