Currently poorly implemented those 2 functions, need to refactor them in a more efficient fashion. Also need to add tests.