refactord A lot better now