finished most of the code