Some improvements to the code (was: horrible; is: poor)