Added a few test, fixed a few edge case scenarios