Initial code, probably buggy!