Added utility methods, fixed NPE