fix error and new pattern matching, sorry for changing something, mail me if you want :D