Updated function, tested and functional.
TODO: create user interface.