Fix corner case calculation