debugged a bit, need to test