Restructure project, extract functions into modules