Enhancements based on comments by @jussimalinen