code optimized

removed unnecessary fxns; added documentation