added error notice. code refactoring