Merging Tommy's code

Merging Tommy's code through master function.