fixed some small bugs, made code more testable