factor out angle calculations