added some unit functions, added pseudocode