mostly completed code