got rid of undefined *buffer* warning
major refactoring