Several code improvements, see readme.txt