initial commit. Seems to work but still might need tweaking