Refactor to shorten and clean functions