Some speedup and enhacements