Merged brendans code