code formatted, psn_free function added