added a bit of defensive programming
updated for v0.2.3