fixed a few bugs, removed a non-functional part of a function