Some improvements from Daniels codereview 2