Small optimization tweaks and modified API