add assertions and exceptions handling