Improved structure, added param structs, improved logging and comments.