added the functioning code. need to make much cleaner