minor optimizations
minor fixing & some JUnit tests added