a lot of improvement in the helper functions