Cleaned up Receiver code

Separated functions and introduced some recursion