Fix bug in top calculation