divided a function
refactoring
fixed a bug