Simplified code a bit
Added implementation for end-of-input
Added tests for checking empty list