Added tests for derivability and funtionality and logic for derivation