Refactored the private variable handling and added more tests.