refactoring for more swifty and add some comments