Split the code into multiple source files

Also increase separation of particular modules.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>