Changed organisation of functions in files

- comments
- minor fixes
- got rid of all warnings