Code cleanup: sparse array handling, etc.

Fixes #302.

_**NOTE:** Will need to be rebased after merging PR #304._