Moved check of capacity after its calculation.