almost finish remove redundancy as subroutine except base correction