Refactoring: initialize all layers at once and avoid duplication of slicing height math. #637