Prefix search algorithm corrected and working properly