fixed build errors, cleaned up a bit
the changes I made may not reflect the actual intentions of the code, but the original code definitely didn't or would've ever compiled