fixed clang warnings, checking errors, commenting code thouroughly.