refactor code over. bug fix.