working version without reg