tidy up; fixed bug in calculateCell