Code cleanup

1. reducing code duplication
2. adding IProxy class for type hinting