Removed unused rfind and removed debug prints.