changed output to optional, implemented toMatrix (Flash)