Refactoring; Fix bugs from crittercism