refactoried all the stuff -- V1