Completed working version 1