Modified to fix bug in init, added unit tests