arranged code into modules a bit