updated code, work in progress