Even closer but very dirty code