working, but has bugs, need improving and refactory