making a few optimizations to make it faster and retro compatible with other libraries