working solution but not very good