Fixes and code improvements