Working file, added more comments
Working function