Refactor code and split them into classes