added data structure and algorithm kinda works