added some fixes to many functions, fixed some tests