renamed some functions, more code commented