somehow working, code needs to be refactor