cleaned up code (mainly delegate functions)