Removed duplicate code
Added related functions