finished most functions, need more testing and handling edge case