dirty code, but it's running ok