first version of the solution. yet to be improved