Improved suffix function