fixed length bug
added unit tests for casting