refactor.
finished basic function.