finished porting logic from java to swift and created string output