added final function + minor changes