cleaned up main code