fixes and code improvements