moved some parts out to separate files