Implemented the changes commented by jlec on commit 6e7b87fe1c457e37b31ec8bb904d653b520cd08d