Better documentation, renamed some variables and functions