fixes and refactoring in Swift.js