reorganized code. Will make gpu version separately