Finished functional version. Tested. Works fine