first, ugly as fuck, but usable version