moved functionality to optlib
Holy crap, it's working.