Removed unused code
Reordered code + added test. No functional change intended