Refactor, need to make more defensive code.