cleaned up, minor optimizations