Split out functionality to separate modules

Signed-off-by: Alexander Berntsen <alexander@plaimi.net>
Signed-off-by: Stian Ellingsen <stian@plaimi.net>
Reviewed-by: Stian Ellingsen <stian@plaimi.net>