initial commit - works, but definitely some ugly code in here