remove unnecessary globals, add documentation