code almost works