almost done, known bug:missing end