Quite a few magic numbers in this function, consider properties please.