Refactored stuff into functions.