Some cleanup #1365

@viddo take a look and improve Ruby part if you want, I wasn't that sure about what would be an improvement.