Implemented a query for source range

Cleaned up code a bit