working but not pretty solution