fixed #3, other bugs
added NullPointerException throw