Separated most of the logic in different files