Fixed redundant code, naming issues and added regression tests