Refactored to be much better