added test code and error fixing