Added test code and removed redundant code