Added local mock creation (messy-but working code).

Some refactorings.