added input preservation, added init() function