fixed issue with alias search and cleaned up the code. If there are multiple aliases generated in a row, now all of them are found.

added some test cases