added final code for beta 1