refactoring js
refactored code, added tracking of captured pieces