added test code, cleaned code