initial commit, full implementation, still needs testing