completed the harder example... it's ugly but it works