first working version - very dirty hack