refactored and changed from buffer sillyness to pointer simplicity