change code structure, add pause and unpause function