finally fixed bug in sba algorithm. still have to test the code if it really is the right thing. and add comments