rewrote some of the code to be more streamlined
fixed the compilation errors in the last commit
fixed a few bugs