after major clean up and added comments seems to be working