misc. cleanup, fix and optimization