Fixes #40 and #41. Thanks @vikhyat

Should fix the above issues.