some performance/bug fixes