added Math.min in case the parent is smaller