Cell code tidied up