cleaned up code for dynamic block