Reorganized code (added lib file)