Fixed some errors like functions declartation not from object and rolled back to Algirdas code