Subtle fix and performance increase

Old function replaced with a new one for performance and fixed a subtle
bug.
Your work is done here

Rest in peace, my prince.