Added tests, refactored and improved branch spec normalization