improved mod4. thanks myles maxfield;