Avoid null by moving length check to start of block