rewritten entire program as class