refactored some code; fixed some bugs; now it works completely for me