Fixed a few bugs. Added a few test cases. Started to re write discover method.