fix fugs, add logging