updated swift code
bug fixes