Minor bug fixes and performance tweaks.

Signed-off-by: SturmB <sturm359@gmail.com>