rewritten entire program