Simplified placing return value at end, and refactored