picked some changes from awakecoding tree