fixing some reference issues and test cases