moved ugly func to the bottom