added if/else to check for even/odd dimensions