Improved some lengthy code